package ltd.dujiabao.capability.adapter.driven.persistence.devmng;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import ltd.dujiabao.capability.common.dto.Result;
import ltd.dujiabao.capability.common.exception.BusinessException;
import ltd.dujiabao.capability.domain.devmng.DevInfo;
import ltd.dujiabao.capability.domain.devmng.DevInfoRepository;

/**
 * @author : DuJiabao
 * @Project : ddd-capability
 * @Time : 2024/4/6 23:15
 * @Desc :
 */
@Repository
public class DevInfoRepositoryImpl implements DevInfoRepository {

    @Autowired
    private DevInfoFeignClient devInfoFeignClient;

    @Autowired
    private DevInfoMapper devInfoMapper;

    @Override
    public DevInfo findByDevId(Long devId) {
        Result<DevInfoDTO> result = devInfoFeignClient.findByDevId(new FindByDevIdDTO(devId));
        if (!result.isSuccess()) {
            throw new BusinessException("Fail to query dev info.", result.getErrorCode());
        }
        return devInfoMapper.toDevInfo(result.getResult());
    }
}
